/*
 * Copyright (c) csii.com.cn 2016 zhaojin
 */

package com.csii.ssm.filter;

import javax.servlet.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 针对请求方式的不同做相应的过滤处理
 *
 * @author zhaojin 15398699939@163.com
 * @create 2016-05-16-下午5:27
 */

public class RequestTypeFilter implements Filter {

    private static final String ACCEPT = "Accept";
    private static final List<String> JSON_ACCEPTS = Arrays.asList(new String[]{"application/json"});

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
//        String accept = httpServletRequest.getHeader(ACCEPT);
        filterChain.doFilter(servletRequest, servletResponse);
//        for (String jaccept : JSON_ACCEPTS) {
//            if (Arrays.asList(accept.split(",")).contains(jaccept)) {
//                //客户端需要返回json类型的数据
//                Object appJsonStatuFlag = httpServletRequest.getAttribute(CommonDict.PAGE_AJAX_STATUS);
//                if (null == appJsonStatuFlag || !StringUtils.isBlank(appJsonStatuFlag.toString())) {
//                    //!错误情况一般抛出异常,或者status已经被设置,这里的处理只是为了在正常情况,不需要在控制器中写下面这段代码
//                    httpServletRequest.setAttribute(CommonDict.PAGE_AJAX_STATUS, CommonDict.PAGE_AJAX_STATUS_SUCCESS);
//                }
//            }
//            break;
//        }
    }

    @Override
    public void destroy() {

    }
}
